package com.zk.algorithm.string;

import com.zk.algorithm.annotation.BianChengZhiMei;

/**
 * 字符串移位包含问题, s1 是否可以通过循环移位来包含 s2
 *
 * s1 = AABCD => s2 = CDAA
 *
 * @author zk
 */
@BianChengZhiMei("3.1")
public class StringRotateContains {

    // s1 = ABCD
    //
    // ABCD → BCDA → CDAB → DABC → ABCD → ...
    //
    // 将前面移走的数据进行保留
    // ABCD → ABCDA → ABCDAB → ABCDABC → ABCDABCD → ...
    //
    // s1s1 包含 s2
    public boolean contains(String s1, String s2) {
        if (s1 == null || s2 == null) {
            return false;
        }

        return (s1 + s1).contains(s2);
    }

}
